class UsersController < ApplicationController
  layout "background"
  
  def index
    @user = User.find(params[:id])
  end
  
  def edit
    @user =User.find(params[:id])
  end
  
  def edit_password
    @user =User.find(params[:id])
  end
  
  def update
    @user = User.find(params[:id])
      if @user.update_attributes(params[:user])
        flash[:notice] = '用户信息修改成功！'
      else
        flash[:notice] = '用户信息修改失败！'
      end
      redirect_to(:action=>"index",:id=>session[:user_id])
  end
  
  def change_password
    
  end
  
  def edit_user_info
    @user =User.find(params[:id])
  end
  
  def user_info_index
    @user = User.find(session[:user_id])
  end
  
  def update_user_info
    @user = User.find(params[:id])
      if @user.update_attributes(params[:user])
        flash[:notice] = '用户信息修改成功！'
      else
        flash[:notice] = '用户信息修改失败！'
      end
      redirect_to(:action=>"user_info_index",:id=>session[:user_id])
  end
  
  def update_password
    user=User.authenticate_by_id(session[:user_id],params[:old_password])
    if user&&params[:new_password]==params[:password_confirm]
       user.password=(params[:new_password])
      if user.save
        flash[:notice]='密码修改成功！' 
      else
        flash[:notice]='密码修改失败！'      
      end        
    end
      redirect_to(:action=>"index",:id=>session[:user_id])
  end
end
